package struct.intermediate.stack;

import struct.primary.linked.LinkedList;

/**
 * @author MAX
 * @version 1.0
 * @description 中级数据结构-链式栈
 * @date 2022/1/13 10:34
 */
public class LinkedStack<E extends Comparable<E>> implements Stack<E> {

    private LinkedList<E> linkedList;

    public LinkedStack() {
        linkedList = new LinkedList<>();
    }

    @Override
    public int size() {
        return linkedList.size();
    }

    @Override
    public boolean isEmpty() {
        return linkedList.isEmpty();
    }

    @Override
    public void push(E e) {
        linkedList.addFirst(e);
    }

    @Override
    public E pop() {
        return linkedList.remove(0);
    }

    @Override
    public E peek() {
        return linkedList.getFirst();
    }

    @Override
    public String toString() {
        return "top [" + linkedList.toString() + "] bottom";
    }
}
